<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>props验证-使用自定义函数验证传入子组件的数据是否符合指定条件</title>
    <script src="vue.js"></script>
  </head>
  <body>
    <div id="app">
      <parent></parent>
    </div>
    <script>
      var childNode = {
        template: "<div>{{ para }}</div>",
        props: {
          para: {
            validator: function (value) {
              return value > 10;
            },
          },
        },
      };
      var parentNode = {
        template: `
      <div class="parent">
           <child :para="num"></child>
      </div>`,
        components: {
          child: childNode,
        },
        data() {
          return {
            num: 5,
          };
        },
      };
      // 创建根实例
      var vm = new Vue({
        el: "#app",
        components: {
          parent: parentNode,
        },
      });
    </script>
  </body>
</html>
